package com.fdhwws.web.dao.impl;

import com.fdh.myjdbcutil.MyJdbcUtil;
import com.fdhwws.web.dao.UserFootprintsDao;
import com.fdhwws.web.domain.UserFootprints;

import java.util.List;

public class UserFootprintsDaoImpl implements UserFootprintsDao {
    @Override
    public UserFootprints selectById(Integer id) {
        return MyJdbcUtil.getInstance()
                .selectSql_upgrade("SELECT * FROM user_footprints WHERE id =?",
                        UserFootprints.class);
    }

    @Override
    public List<UserFootprints> selectAll() {
        return MyJdbcUtil.getInstance()
                .selectAll_upgrade("SELECT * FROM user_footprints",
                        UserFootprints.class);
    }

    @Override
    public int insert(UserFootprints entity) {
        return MyJdbcUtil.getInstance()
                .insertSql_upgrade(entity);
    }

    @Override
    public int update(UserFootprints entity) {
        return MyJdbcUtil.getInstance()
                .updateSql_upgrade(entity);
    }

    @Override
    public int delete(Integer id) {
        return MyJdbcUtil.getInstance()
                .updateSql("DELETE FROM user_footprints WHERE id =?", new Object[]{id});
    }

    @Override
    public UserFootprints selectByUidAndRoomId(Integer uid, Integer roomId) {
        return MyJdbcUtil.getInstance()
                .selectSql_upgrade("SELECT * FROM user_footprints WHERE uid =? AND room_id =?",
                        new Object[]{uid, roomId},
                        UserFootprints.class);
    }

    @Override
    public List<UserFootprints> selectAllByUid_orderByTime(Integer uid) {
        return MyJdbcUtil.getInstance()
                .selectAll_upgrade("SELECT * FROM user_footprints WHERE uid =? ORDER BY time DESC",
                        new Object[]{uid},
                        UserFootprints.class);
    }
}
